﻿// -----------------------------------------------------------------------
// <copyright file="CounterHistory_DAL.cs" company="">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace PMSGSC.DAL
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class CounterHistory_DAL: BaseDAL
    {
        // Lấy tất cả HistoryCounter
        public static List<HistoryCounter> GetAll(int shipID)
        {
            DB.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, DB.HistoryCounters);
            return DB.HistoryCounters.Where(n => n.Equipment.Ship_ID == shipID).ToList();
        }
        // Lấy HistoryCounter theo Id
        public static HistoryCounter GetDataById(int id)
        {
            return DB.HistoryCounters.Where(m => m.HistoryCounters_ID == id).FirstOrDefault();
        }
        //Thêm một HistoryCounter
        public static bool Insert(HistoryCounter HistoryCounter)
        {
            try
            {
                DB.HistoryCounters.InsertOnSubmit(HistoryCounter);
                DB.SubmitChanges();
                return true;
            }
            catch
            {
                return false;
            }

        }
        // Xóa một HistoryCounter
        public static bool Delete(HistoryCounter HistoryCounter)
        {
            try
            {
                DB.HistoryCounters.DeleteOnSubmit(HistoryCounter);
                DB.SubmitChanges();
                return true;
            }
            catch
            {
                return false;
            }

        }
    }
}
